package cn.ac.aircas.web.controller.system;

import cn.ac.aircas.common.core.controller.BaseController;
import cn.ac.aircas.common.core.domain.AjaxResult;
import cn.ac.aircas.common.core.page.TableDataInfo;
import cn.ac.aircas.common.utils.RoadUtils;
import cn.ac.aircas.system.domain.RoadConditionPoint;
import cn.ac.aircas.system.domain.RoadConditionTab;
import cn.ac.aircas.system.service.IRoadPointService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/road/point")
public class SysRoadPointController extends BaseController {
    @Resource
    IRoadPointService roadPointService;

    /**
     * 更新道路状态
     *
     * @param road
     * @return
     */
    @PostMapping("/update")
    public AjaxResult updateRoadConditionStatus(RoadConditionPoint road) {
        int res = roadPointService.updateRoadPointConditionStatus(road);
        RoadUtils.clearUnderCache();
        return AjaxResult.success(res);
    }

    /**
     * 分页查询异常道路
     *
     * @param road
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo selectRoadConditionList(RoadConditionPoint road) {
        startPage();
        List<RoadConditionPoint> list = roadPointService.selectRoadPointConditionList(road);
        return getDataTable(list);
    }

    @GetMapping("/{conditionId}")
    public AjaxResult getRoad(@PathVariable Long conditionId) {
        return success(roadPointService.getRoadPoint(conditionId));
    }

    @DeleteMapping("/{conditionIds}")
    public AjaxResult remove(@PathVariable Long[] conditionIds) {
        int res = roadPointService.deleteRoadPointByIds(conditionIds);
        RoadUtils.clearUnderCache();
        return toAjax(res);
    }
}
